export function createPages(dataArr, container) {
    function createItem(index) {
        const item = document.createElement('div');
        item.classList.add('item');

        let str = '';
        if (index == 0) { // homePage页
            const title = dataArr[index].title;
            dataArr[index].classify.forEach((item) => {
                str += `
                    <li>
                        <p>${item}</p>
                    </li>
                `
            })
            item.innerHTML = `
            	<div class="itemBox">
                    <div class="homePage">
                        <p class="homeTitle">${title}</p>
                        <ul>${str}</ul>
                    </div>
                </div>
            `;
        } else { // 其他内容页
            const title = dataArr[index][0].title;
            dataArr[index].forEach((item, index) => {
                if (index != 0) {
                    str += `<li><div>
                        <h4>${item.name}<span>${item.time}</span></h4>
                        <div class="hideBox">`

                    for (let key in item['files']) {
                        str += `
                            <a target="_blank" href="${item['files'][key]}">${key}</a>
                        `
                    }
                    str += `</div></div></li>`
                }
            })
            item.innerHTML = `
            	<div class="itemBox">
                    <div class="itemPage">
                        <h2>${title}（${dataArr[index].length - 1}）</h2>
                        <div class="itemContent">
                            <ul>${str}</ul>
                            <div class="resize">1</div>
                            <div class="preWindow">
                                markdown展示区
                            </div>
                        </div>
                    </div>
                </div>
            `;
        }
        container.appendChild(item);
        return item;
    };

    // dataArr.forEach((item,ind)=>{
    //     console.log(ind);
    //     createItem(ind)
    // })

    // 根据当前坐标确定下一项和上一项
    function resetElements(currentIndex) {
        container.innerHTML = '';
        const prevIndex = currentIndex - 1 < 0 ? dataArr.length - 1 : currentIndex - 1;
        const nextIndex = currentIndex + 1 > dataArr.length - 1 ? 0 : currentIndex + 1;

        // 创建上、中、下三个 div
        createItem(prevIndex).classList.add('prev');
        createItem(currentIndex).classList.add('cur');
        createItem(nextIndex).classList.add('next');
    }

    return {
        createItem: createItem,
        resetElements: resetElements
    };
}